# python3.7
# -*- coding: UTF-8 -*-

import pefile
import os
import glob
def 读取指定类型文件名(folder_path):
    # folder_path = r'C:\Windows\System32'
    file_extension = ".dll"
    files = glob.glob(os.path.join(folder_path, "*" + file_extension))  # 完整路径
    files2 = []
    for file in files:
        mz = (file.split('\\')[-1]).upper()
        files2.append(mz)

    return files2

# 打开 DLL 文件
dll_file = pefile.PE(r'C:\Program Files\Mapi\Mapi_CTP\x64\CTP\CTP_SE_Trade_x64.dll')
s32 = 读取指定类型文件名(r'C:\Windows\System32')  # System32  # SysWOW64
# print(s32)

# 获取导入表
imports = dll_file.DIRECTORY_ENTRY_IMPORT
# 遍历导入表中的所有 DLL
for imp in imports:
    dllming = (imp.dll.decode('utf-8')).upper()
    dllming2 = (imp.dll.decode('utf-8'))
    # print(f"Imported DLL: {dllming}")
    if dllming not in s32:
        print(dllming, '   不存在,原来名称:', dllming2)

    # # 遍历每个 DLL 导入的函数
    # for imp_func in imp.imports:
    #     print(f"Imported function: {imp_func.name.decode('utf-8')}")
